<?php

namespace yida;

use ShidianUtil\Exception\ErrorCode;
use ShidianUtil\Thinkphp\Response\ApiResponse;
use think\response\Json;

/**
 * 接口响应
 * Class YidaResponse
 * @package yida
 */
class YidaResponse extends ApiResponse
{
    /**
     * 请求成功
     * @param mixed $data
     * @return ApiResponse
     */
    public static function success($data): ApiResponse
    {
        $output = [
            'success' => true,
            'content' => $data,
        ];
        return invoke(self::class, [$output, 200]);
    }

    /**
     * 请求失败
     * @param string $desc
     * @param int $code
     * @param null $data
     * @return ApiResponse
     */
    public static function fail(string $desc, int $code = ErrorCode::FAIL, $data = null): ApiResponse
    {
        $output = [
            'success' => false,
            'error' => [
                'message' => $desc,
            ],
            'content' => $data,
        ];

        return invoke(self::class, [$output, 200]);
    }
}
